export function permission (permiseData,rootDom) {
    function PagePermission(permiseData,rootDom){
           this.permiseData = permiseData;
           this.rootDom = document.body||rootDom;
           this.permiseElement = [];
           this.init();
    }
    PagePermission.prototype = {
        constructor:PagePermission,
        getPermiseEl: function getPermiseEl(rootDom){
            if(!rootDom) return;
            if(rootDom.getAttribute('permise')&&rootDom.getAttribute('permise')!=''){
               this.permiseElement.push(rootDom);
            }
            for (var i = 0; i < rootDom.children.length; i++) {
                this.getPermiseEl(rootDom.children[i]) //递归调用
            }
        },
        controlEl: function controlEl(permiseElement){
            var _this = this;
            permiseElement.forEach(function (item) {     
                if(_this.permiseData.indexOf(item.getAttribute('permise'))===-1&&item.style!=="none"){
                    item.style.display = 'none';
                }
            })
        },
        reload:function reload() {
            this.getPermiseEl(this.rootDom);
            this.controlEl(this.permiseElement);
        },
        init: function init(){
            this.getPermiseEl(this.rootDom);
            this.controlEl(this.permiseElement);
        },
    }
   
       if (!Array.isArray(permiseData)) return new TypeError('permiseData type must be an Array');
       if(typeof rootDom !=="object" || rootDom.nodeType!==1) return new TypeError("rootDom type must be a obeject && dom")
       return  new PagePermission(permiseData,rootDom);
}
